﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartRFIDSystem19.model
{
    class Captcha
    {
        //返回指定位数的随机大小写字母和数字的字符串作为验证码
        public static string GetRandomCode(int length)
        {
            string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            StringBuilder sb = new StringBuilder();
            Random r = new Random();
            for (int i = 0; i < length; i++)
            {
                int index = r.Next(0, str.Length);
                sb.Append(str[index]);
            }
            return sb.ToString();
        }
        //校验两个字符串是否相等，不区分大小写
        public static bool CheckCode(string code1, string code2)
        {
            //if ((code1 != null) && (code2 != null)) return false;
            if (((code1 != null) && (code2 != null))&&code1.ToLower().Equals(code2.ToLower()))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
